home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / p4 / p4-1_2c.lha / p4-1.2c / lib / p4_shmem_sr.c < prev    next >
C/C++ Source or Header  |  1993-05-24  |  2KB  |  83 lines

  1. #include "p4.h"
  2. #include "p4_sys.h"
  3.  
  4. P4BOOL shmem_msgs_available()
  5. {
  6.     int rc, qidx;
  7.     struct p4_msg_queue *mq;
  8.  
  9.     qidx = p4_local->my_id - p4_global->low_cluster_id;
  10.     mq = &(p4_global->shmem_msg_queues[qidx]);
  11.     rc = (mq->first_msg != NULL);
  12.     return (rc);
  13. }
  14.  
  15.  
  16. struct p4_msg *shmem_recv()
  17. {
  18.     struct p4_msg_queue *mq;
  19.     struct p4_queued_msg *q;
  20.     struct p4_msg *m;
  21.     int my_qidx, from_qidx;
  22.  
  23.     my_qidx = p4_local->my_id - p4_global->low_cluster_id;
  24.     mq = &(p4_global->shmem_msg_queues[my_qidx]);
  25.     p4_dprintfl(60, "receiving shmem messages %d\n", my_qidx);
  26.  
  27.     p4_menter(&mq->m);
  28.     if (mq->first_msg == NULL)
  29.     {
  30.     p4_mdelay(&mq->m, 0);
  31.     }
  32.     q = mq->first_msg;
  33.     if (mq->first_msg == mq->last_msg)
  34.     {
  35.     mq->first_msg = NULL;
  36.     mq->last_msg = NULL;
  37.     }
  38.     else
  39.     mq->first_msg = mq->first_msg->next;
  40.     p4_mcontinue(&mq->m, 0);
  41.  
  42.     from_qidx = q->qmsg->from - p4_global->low_cluster_id;
  43.     if (q->qmsg->ack_req & P4_ACK_REQ_MASK)
  44.     {
  45.     p4_dprintfl(30, "sending ack to %d\n", q->qmsg->from);
  46.     p4_unlock(&(p4_global->shmem_msg_queues[from_qidx].ack_lock));
  47.     p4_dprintfl(30, "sent ack to %d\n", q->qmsg->from);
  48.     }
  49.  
  50.     m = q->qmsg;
  51.     free_quel(q);
  52.     p4_dprintfl(60, "received from %d via shmem\n", q->qmsg->from);
  53.     return (m);
  54. }                /* shmem_recv */
  55.  
  56.  
  57. int shmem_send(tmsg)
  58. struct p4_msg *tmsg;
  59. {
  60.  
  61.     struct p4_msg_queue *mq;
  62.     int from, to_qidx, from_qidx;
  63.  
  64.     p4_dprintfl(20, "sending msg of type %d from %d to %d via shmem\n",tmsg->type,tmsg->from,tmsg->to);
  65.     to_qidx = tmsg->to - p4_global->low_cluster_id;
  66.     from_qidx = tmsg->from - p4_global->low_cluster_id;
  67.     mq = &(p4_global->shmem_msg_queues[to_qidx]);
  68.  
  69.     p4_menter(&mq->m);
  70.     queue_p4_message(tmsg, mq);
  71.     p4_mcontinue(&mq->m, 0);
  72.  
  73.     if (tmsg->ack_req & P4_ACK_REQ_MASK)
  74.     {
  75.     p4_dprintfl(30, "waiting for ack from %d\n", tmsg->to);
  76.     p4_lock(&(p4_global->shmem_msg_queues[from_qidx].ack_lock));
  77.     p4_dprintfl(30, "received ack from %d\n", tmsg->to);
  78.     }
  79.     p4_dprintfl(10, "sent msg of type %d from %d to %d via shmem\n",tmsg->type,tmsg->from,tmsg->to);
  80.  
  81.     return (0);
  82. }
  83.